<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		session_start();
			if ($_SESSION['userid'] < 1)
			{
				redirect('welcome/index','refresh');
			};	
	}
	
	function index()
	{
		$data['title'] = "Manage Users";
		$data['main'] = 'admin/users_home';
		$data['users'] = $this->Users_model->getAllUsers();
		$data['tinymce'] = '';
		$this->load->vars($data);
		$this->load->view('admin/dashboard');
	}
	
	function create()
	{
		$this->load->library('encrypt');
		if ($this->input->post('username'))
		{
			$this->Users_model->addUser();
			redirect('admin/users/index','refresh');
		}
		else
		{
			$data['title'] = "Create User";
			$data['main'] = 'admin/users_create';
			$data['tinymce'] = '';
			$this->load->vars($data);
			$this->load->view('admin/dashboard');
		}
	}


	function edit($id=0)
	{
		$this->load->library('encrypt');
		if ($this->input->post('username'))
		{
		  $this->Users_model->updateUser();
		  redirect('admin/users/index','refresh');
		}
		else
		{
			$data['title'] = "Edit User";
			$data['main'] = 'admin/users_edit';
			$data['users'] = $this->Users_model->getUser($id);
			$data['tinymce'] = '';
			$this->load->vars($data);
			$this->load->view('admin/dashboard');
		}
	}

	function delete($id)
	{
		$this->Users_model->deleteUser($id);
		redirect('admin/users/index','refresh');
	}
	
}//end class

/* End of file users.php */
/* Location: ./application/controllers/admin/users.php */

